function change() {
    window.location = '/register';
}

function log() {
    var username = document.getElementById("username").value;
    var pwd = document.getElementById("password").value;
    if (username == "") {
        alert("账号不能为空");
        return false;
    }
    if (pwd == "") {
        alert("密码不能为空");
        return false;
    }

    // 使用Ajax请求与后端交互
    var xhr = new XMLHttpRequest();
    xhr.open("POST", "/login", true);
    xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
    xhr.onreadystatechange = function() {
        if (xhr.readyState == 4 && xhr.status == 200) {
            var response = JSON.parse(xhr.responseText);
            if (response.success) {
                sessionStorage.setItem("user", JSON.stringify(response.member)); // 存储用户信息
                window.location = "/index";
            } else {
                alert(response.message);
            }
        }
    };
    xhr.send(JSON.stringify({username: username, password: pwd}));
}
